package com.changgou.goods.handler;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//统一异常处理类
@ControllerAdvice //用来统一异常处理的注解，是全局注解
public class BaseExceptionHandler {

    @ExceptionHandler(value = Exception.class) //捕获异常的类型
    @ResponseBody
    public Result error(Exception e) {
        //打印异常到后台
        e.printStackTrace();
        //返回统一信息到前台
        return new Result(false, StatusCode.ERROR, "系统繁忙，请稍后重试≧ ﹏ ≦");
    }
}
